package com.thoughtservice.jspdoc.processors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.thoughtservice.jspdoc.JSPFileList;
import com.thoughtservice.jspdoc.JSPPage;
import com.thoughtservice.jspdoc.RE;
import com.thoughtservice.jspdoc.RESyntaxException;

public class ProcessPageImports implements DocProcessor{

	private final static Logger LOG = LoggerFactory.getLogger(ProcessPageImports.class);
	 
	public boolean process(JSPPage p, String pc, JSPFileList fileList)
			throws RESyntaxException {
		LOG.trace("Entering {} ", "ProcessPageImports");
		// Find page tag
		RE re;
		re = new RE("<%[:space:]*@[:space:]*page[:space:]*.*?import=\"([:print:]*?)\"[:print:]*%>");
		String[] matchRes = re.getAllMatches(pc, 1);

		for(int results=0; results < matchRes.length; results++) {
		    re = new RE(",");
		    String[] packages = re.split(matchRes[results]);

		    for(int i = 0; i < packages.length; i++) {
		        p.addImport(packages[i]);
		    }
		}
		LOG.trace("Exiting {} ", "ProcessPageImports");
	
		return false;
	}

}
